//
//  CarInfoTableViewCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/10/18.
//

import UIKit

class CarInfoTableViewCell: UITableViewCell {
    var carImageView: UIImageView!
    var nameLab: UILabel!
    var totalPriceLab: UILabel!
    var priceLab: UILabel!
    var seaCarFlag: Bool = false
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = .white
        self.clipsToBounds = true
        self.initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        
        self.carImageView = UIImageView(frame: .zero)
        self.contentView.addSubview(self.carImageView)
      
        self.nameLab = UILabel(frame: .zero)
        self.nameLab.textColor = Theme.titleLabColor
        self.nameLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 14)
        self.nameLab.textAlignment = .left
        self.nameLab.numberOfLines = 0
        self.contentView.addSubview(self.nameLab)
        
        
        self.totalPriceLab = UILabel(frame: .zero)
        self.totalPriceLab.textColor = Theme.titleLabColor
        self.totalPriceLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        self.totalPriceLab.textAlignment = .left
        self.contentView.addSubview(self.totalPriceLab)
        
        
        self.priceLab = UILabel(frame: .zero)
        self.priceLab.textColor = Theme.titleLabColor
        self.priceLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 20)
        self.priceLab.textAlignment = .left
        self.contentView.addSubview(self.priceLab)
        
        self.addLayout()
        
    }
    
    func addLayout(){
        
        self.carImageView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(280)
        }
        
        self.nameLab.snp.makeConstraints { make in
            make.top.equalTo(self.carImageView.snp.bottom).offset(14)
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.height.greaterThanOrEqualTo(20)
        }
        
        self.totalPriceLab.snp.makeConstraints { make in
            make.top.equalTo(self.nameLab.snp.bottom).offset(20)
            make.left.equalTo(14)
            make.height.equalTo(20)
        }
        
        self.priceLab.snp.makeConstraints { make in
            make.top.equalTo(self.nameLab.snp.bottom).offset(16)
            make.left.equalTo(self.totalPriceLab.snp.right).offset(4)
            make.height.equalTo(28)
            make.bottom.equalTo(-4)
        }
        
    }
    
    
    
    //setModel
    func setModel(model: CarDetailsContentModel){
        self.carImageView.sd_setImage(with: URL(string: model.backgroundImage ?? ""))
        self.nameLab.text = model.name ?? ""
        self.totalPriceLab.text = MMLocalizedString("total_value", comment: "总价")
        
        var price = XTManageCenter.showPriceInComma(source: (model.price ?? 0).cleanZero)
        self.priceLab.text = XTManageCenter.currentSign() + price
        self.updateConstraints()
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
